package fr.umlv.m2.jee.spij.persistence.education;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Entity KeyWord who contain a keyword linked to units.
 *
 * @author Lounes Akroune
 * @author Aurelien Scelles
 */
@Entity
@Table(name = "KEY_KEYWORD")
public class KeyWord implements Serializable {

    /**
     * Primary key.
     */
    @Id
    @Column(name = "KEY_ID", nullable = false, unique = true, updatable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /**
     * The keyword.
     */
    @Column(name = "KEY_WORDING", nullable = false, unique = true)
    private String wording;

    /**
     * Link between keywords and units.
     */
    @ManyToMany(cascade = {CascadeType.ALL}, mappedBy = "keyWords")
    private List<Unit> units = new ArrayList<Unit>();

    /**
     * Setter of Id.
     *
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Getter of Id.
     *
     * @return primary key
     */
    public long getId() {
        return id;
    }

    /**
     * Setter of Wording.
     *
     * @param wording
     */
    public void setWording(String wording) {
        this.wording = wording;
    }

    /**
     * Getter of Wording.
     *
     * @return keyword
     */
    public String getWording() {
        return wording;
    }

    /**
     * Setter of linked Units.
     *
     * @param units
     */
    public void setUnits(List<Unit> units) {
        this.units = units;
    }

    /**
     * Getter of linked Units.
     *
     * @return list of units linked
     */
    public List<Unit> getUnits() {
        return units;
    }

}
